package com.basic.business.common.execption;

import com.basic.business.common.constant.ResultMsgEnum;
import com.basic.business.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author ：huage
 * @date ：Created in 2021/7/20 17:54
 * @description： 统一处理返回前端的错误信息
 */
@ControllerAdvice
@Slf4j
public class CustomerExceptionHandler {

    @ExceptionHandler
    @ResponseBody
    public String ErrorHandler(AuthorizationException e) {
        log.error("没有通过权限验证！", e);
        return "没有通过权限验证！";
    }

    @ExceptionHandler
    @ResponseBody
    public Result ErrorHandler(AuthException e) {
        log.error("没有通过权限验证！", e);
        return Result.error(ResultMsgEnum.AUTH_ERROR.getCode(),ResultMsgEnum.AUTH_ERROR.getMessage());
    }

    @ExceptionHandler
    @ResponseBody
    public Result Execption(Exception e) {
        log.error("未知异常！", e);
        return Result.error(ResultMsgEnum.SERVER_BUSY.getCode(),ResultMsgEnum.SERVER_BUSY.getMessage());
    }
}
